<a href='https://github.com/angular/angular.js/edit/v1.5.x/src/ng/window.js?message=docs($window)%3A%20describe%20your%20change...#L3' class='improve-docs btn btn-primary'><i class="glyphicon glyphicon-edit">&nbsp;</i>Improve this Doc</a>



<a href='https://github.com/angular/angular.js/tree/v1.5.8/src/ng/window.js#L3' class='view-source pull-right btn btn-primary'>
  <i class="glyphicon glyphicon-zoom-in">&nbsp;</i>View Source
</a>


<header class="api-profile-header">
  <h1 class="api-profile-header-heading">$window</h1>
  <ol class="api-profile-header-structure naked-list step-list">
    
  

    <li>
      - service in module <a href="api/ng">ng</a>
    </li>
  </ol>
</header>



<div class="api-profile-description">
  <p>A reference to the browser&#39;s <code>window</code> object. While <code>window</code>
is globally available in JavaScript, it causes testability problems, because
it is a global variable. In angular we always refer to it through the
<code>$window</code> service, so it may be overridden, removed or mocked for testing.</p>
<p>Expressions, like the one defined for the <code>ngClick</code> directive in the example
below, are evaluated with respect to the current scope.  Therefore, there is
no risk of inadvertently coding in a dependency on a global value in such an
expression.</p>

</div>






<div>
  

    

  

  
  
  



  
  <h2 id="example">Example</h2><p>

<div>
  <plnkr-opener example-path="examples/example-example109"></plnkr-opener>

  <div class="runnable-example"
      path="examples/example-example109"
      module="windowExample">

  
    <div class="runnable-example-file" 
      name="index.html"
      language="html"
      type="html">
      <pre><code>&lt;script&gt;&#10;  angular.module(&#39;windowExample&#39;, [])&#10;    .controller(&#39;ExampleController&#39;, [&#39;$scope&#39;, &#39;$window&#39;, function($scope, $window) {&#10;      $scope.greeting = &#39;Hello, World!&#39;;&#10;      $scope.doGreeting = function(greeting) {&#10;        $window.alert(greeting);&#10;      };&#10;    }]);&#10;&lt;/script&gt;&#10;&lt;div ng-controller=&quot;ExampleController&quot;&gt;&#10;  &lt;input type=&quot;text&quot; ng-model=&quot;greeting&quot; aria-label=&quot;greeting&quot; /&gt;&#10;  &lt;button ng-click=&quot;doGreeting(greeting)&quot;&gt;ALERT&lt;/button&gt;&#10;&lt;/div&gt;</code></pre>
    </div>
  
    <div class="runnable-example-file" 
      name="protractor.js"
      type="protractor"
      language="js">
      <pre><code>it(&#39;should display the greeting in the input box&#39;, function() {&#10; element(by.model(&#39;greeting&#39;)).sendKeys(&#39;Hello, E2E Tests&#39;);&#10; // If we click the button it will block the test runner&#10; // element(&#39;:button&#39;).click();&#10;});</code></pre>
    </div>
  

    <iframe class="runnable-example-frame" src="examples/example-example109/index.html" name="example-example109"></iframe>
  </div>
</div>


</p>

</div>


